<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>用户信息-修改</title>
    <meta name="description" content="这是一个用户信息页面">
    <meta name="keywords" content="用户信息">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="${contextPath}/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="${contextPath}/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="${contextPath}/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="${contextPath}/assets/css/amazeui.chosen.css"/>
    <link rel="stylesheet" href="${contextPath}/assets/css/amazeui.datatables.min.css"/>
    <link rel="stylesheet" href="${contextPath}/assets/css/app.css">
    <script src="${contextPath}/assets/js/jquery.min.js"></script>

</head>

<body data-type="widgets">
<script src="${contextPath}/assets/js/theme.js"></script>
<div class="am-g tpl-g">
    <!-- 头部 -->
    <#include "/pc/common/header.html" />
    <!-- 侧边导航栏 -->
    <#include "/pc/common/left.html" />
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <ol class="am-breadcrumb widget-head">
                            <li><a href="${contextPath}/index.htm" class="am-icon-home">首页</a></li>
                            <li>系统管理</li>
                            <li><a href="${contextPath}/user/list.htm">用户管理</a></li>
                            <#if user?? && user.id??>
                                    <li>修改</li>
                                <#else>
                                    <li>新增</li>
                            </#if>
                        </ol>
                        <div class="widget-body  am-fr">
                            <div class="am-u-sm-12">
                                <form class="am-form am-form-horizontal"
                                      action="${contextPath}/user/save.htm" method="post" id="myform">
                                    <fieldset>
                                        <#if user?? && user.id??>
                                            <input type="hidden" id="id" name="id" value="${user.id!}">
                                        </#if>
                                        <div class="am-form-group">
                                            <label for="doc-ipt-3" class="am-u-sm-2 am-form-label">用户名</label>
                                            <div class="am-u-sm-10">
                                                <input type="text" id="doc-ipt-3" class="required" name="loginName" placeholder="输入用户名"
                                                <#if user?? && user.id??>readOnly=readOnly</#if>
                                                value="${user.loginname!''}">
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label for="doc-ipt-1"
                                                   class="am-u-sm-2 am-form-label">联系电话</label>
                                            <div class="am-u-sm-10">
                                                <input id="doc-ipt-1" type="number" name="tel" class="required"
                                                       placeholder="输入联系电话" value="${user.tel!''}">
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label for="doc-ipt-2"
                                                   class="am-u-sm-2 am-form-label">真实姓名</label>
                                            <div class="am-u-sm-10">
                                                <input type="text" id="doc-ipt-2" name="realName" class="required"
                                                       value="${user.realname!''}" placeholder="输入真实姓名">
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label for="doc-ipt-4"
                                                   class="am-u-sm-2 am-form-label">所属城市</label>
                                            <div class="am-u-sm-10">
                                                <select id="doc-ipt-4" name="cityId" onchange="selectCity(this)" placeholder="请选择所属城市" class="xb_a required" style="margin-left:0px;">
                                                    <#if myjsid==2>
                                                        <#if user.cityid??>
                                                            <#assign cityid="${user.cityid?c}" />
                                                        </#if>
                                                        ${dict.getCityOptions(cityid!)}
                                                        <#elseif myjsid==3>
                                                            <option selected value="${Session.manager_user.cityid}">${dict.getCityName(Session.manager_user.cityid?c)}</option>
                                                    </#if>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label for="doc-ipt-6"
                                                   class="am-u-sm-2 am-form-label">角色</label>
                                            <div class="am-u-sm-10">
                                                <select id="doc-ipt-6" onchange="selectJs(this)" placeholder="请选择角色" name="jsid" class="required" style="margin-left:0px;">
                                                    <#if myjsid==2>
                                                        <#if jsid??>
                                                            <#assign jsId="${jsid?c}" />
                                                        </#if>
                                                        ${dict.getjsOptions(jsId!)}
                                                        <#elseif myjsid==3>
                                                            <option selected value="4">合作商</option>
                                                    </#if>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="am-form-group hzsdiv">
                                            <label for="my-select" class="am-u-sm-2 am-form-label">合作商</label>
                                            <div class="am-u-sm-10">
                                                <select id="my-select" name="merchantid" data-placeholder="选择合作商(输入合作商名称搜索)" style="min-width:300px;" class="chosen-select" tabindex="7">
                                                    <option value=""></option>
                                                    <#if merchant_list??>
                                                        <#list merchant_list as l>
                                                            <option value="${l.id!}" <#if user.merchantid?? && user.merchantid==l.id>selected</#if> >
                                                                ${l.mtname!}&nbsp;(${l.provincename!}${l.cityname}${l.regionname})
                                                            </option>
                                                        </#list>
                                                    </#if>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="am-u-sm-10 am-u-sm-offset-2">
                                            <button type="button" onclick="sub()" class="am-btn am-btn-primary">
                                                保存
                                            </button>
                                            <#if user?? && user.id??>
                                            <button type="button" onclick="resetPassword(${user.id!})" class="am-btn am-btn-warning">
                                                重置密码
                                            </button>
                                            </#if>
                                            <a href="javascript:history.back();"
                                               class="am-btn am-btn-default">返回</a>
                                        </div>
                                    </fieldset>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<#include "/pc/common/alert.html" />
<script src="${contextPath}/assets/js/amazeui.min.js"></script>
<script src="${contextPath}/assets/js/amazeui.chosen.min.js"></script>
<script src="${contextPath}/assets/js/amazeui.datatables.min.js"></script>
<script src="${contextPath}/assets/js/dataTables.responsive.min.js"></script>
<script src="${contextPath}/assets/js/amazeui.page.js"></script>
<script src="${contextPath}/assets/js/app.js"></script>
<script src="${contextPath}/assets/js/amazeui.dialog.min.js"></script>
<script>
    $(document).ready(function(){
        $('#my-select').trigger('chosen:updated');
        $('#my-select').chosen({
            disable_search_threshold: 5,
            no_results_text:"没有找到合作商"
        });
        var jsid = $("#doc-ipt-6").val();
        if(!jsid || jsid!='4'){
            $(".hzsdiv").hide();
        }
    });
    function selectJs(obj){
        var jsid = $(obj).val();
        if(jsid && jsid=='4'){
            $(".hzsdiv").show();
        }else{
            $(".hzsdiv").hide();
        }
    }
    function selectCity(obj){
        var cityid = $(obj).val();
        if(cityid){
            $.ajax({
                url: "${contextPath}/user/merchants.htm?cityId=" + cityid,
                type: "get",
                success: function (data) {
                    var json = $.parseJSON(data);
                    if(json.isSuccess){
                        $('#my-select').html(json.merchants);
                        $('#my-select').trigger('chosen:updated');
                        $('#my-select').chosen({
                            disable_search_threshold: 5,
                            no_results_text:"没有找到合作商"
                        });
                    }
                }
            });
        }
    }
    function resetPassword(id){
        Mconfirm("确定要重置密码吗？",function () {
            $.ajax({
                url: "${contextPath}/user/resetpassword.htm?id=" + id,
                type: "get",
                success: function (data) {
                    Malert(data);
                }
            });
        });
    }
    function sub() {
        var userid = $("#id").val();
        if(userid){
            $("#myform").submit();
        }else{
            var sub_type = true;
            var loginName = $("#doc-ipt-3").val();
            $(".required").each(function () {
                if(!$(this).val()){
                    AMUI.dialog.alert({ title: '错误提示', content: $(this).attr("placeholder"), onConfirm: function() {} });
                    sub_type = false;
                    return false;
                }
            });
            if(!sub_type){
                return false;
            }
            $.ajax({
                url: "${contextPath}/user/checkloginname.htm?loginName=" + loginName,
                type: "get",
                success: function (data) {
                    if (!data) {
                        Malert("用户名为空或者已经存在");
                    } else {
                        $("#myform").submit();
                    }
                }
            });
        }
    }
</script>
</body>

</html>